using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using SCRUMPoker.Web;
using System.Collections.Generic;

namespace SCRUMPoker
{
    public partial class GamesListForm : Page, IGameListView
    {
        public GamesListForm()
        {
            new GamesListPresenter(this, new SessionAdapter(),
                new AppAdapter());
        }
        private IList<Game> _CurrentGames = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            RebindView();
        }

        private void RebindView()
        {
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            if( CreateGame != null)
            {
                CreateGame(sender, e);
            }
        }

        protected void Timer1_Tick(object sender, EventArgs e)
        {
            RebindView();
        }
        
        
        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            ScrumPokerApp.RemoveGame(((Button)sender).CommandArgument.ToString());
        }

        protected void LinkButton1_Click1(object sender, EventArgs e)
        {
            if (GoToGame != null)
            {
                GoToGame(((LinkButton)sender).Text, EventArgs.Empty);
            }
            Response.Redirect("~/Game.aspx");
        }

        public IList<Game> CurrentGames
        {
            get { return _CurrentGames; }
            set
            {
                _CurrentGames = value;
                GridView1.DataBind();
            }
        }

        public string GameSubject
        {
            get { return TextBox1.Text; }
            set { TextBox1.Text = value; }
        }

        public event EventHandler CreateGame;

        public event EventHandler DeleteGame;

        public event EventHandler GoToGame;
    }
}